package com.soft.javase.day14.fileupload;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/5/24
 */
public class FileUploadClient {
    public static void main(String[] args) {
        try (
                Socket socket = new Socket("127.0.0.1", 6666);
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\BrowserDownload\\java.png"));
                BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream())
        ) {
            System.out.println("文件开始上传");
            byte[] buffer = new byte[8192];
            int len;
            while ((len = bis.read(buffer)) != -1) {
                bos.write(buffer, 0, len);
            }
            bos.flush();
            System.out.println("文件上传完成");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
